package cacy.leetcode.linkedList;

import java.util.LinkedList;

/**
 * Project: LeetcodePractice
 * Package: cacy.leetcode.practice20250217
 * Class:   LinkedList01
 * Description:
 * 书店店员有一张链表形式的书单，每个节点代表一本书，节点中的值表示书的编号。
 * 为更方便整理书架，店员需要将书单倒过来排列，就可以从最后一本书开始整理，逐一将书放回到书架上。请倒序返回这个书单链表。
 * 示例 1：
 *     输入：head = [3,6,4,1]
 *     输出：[1,4,6,3]
 * 提示：
 *     0 <= 链表长度 <= 10000
 * @Date: 2025/2/17 周一
 * @Time: 13:46
 * @Author: 凯齐
 */

class Solution01 {
    public int[] reverseBookList(ListNode head) {
        LinkedList<Integer> stack = new LinkedList<Integer>();
        while (head != null) {
            stack.push(head.val);
            head = head.next;
        }
        int[] res = new int[stack.size()];
        for (int i = 0; i < res.length; i++) {
            res[i] = stack.pop();
        }
        return res;
    }
}

public class LinkedList01 {
    public static void main(String[] args) {
        ListNode head = new ListNode(3);
        head.push(6);
        head.push(4);
        head.push(1);
        int[] res = new Solution01().reverseBookList(head);
        for (int i = 0; i < res.length; i++) {
            System.out.print(res[i] + " ");
        }
    }
}
